package com.xx.springboot.DataStructure.LeetCode.Array;

import java.util.Arrays;

/**
 * Created by xiaoxiunique on 2018-8-13.
 */
public class removeDuplicates {
    public int removeDuplicates(int[] nums) {
        if(nums.length == 0)
            return 0;

        int temp = nums[0];
        int len = 1;
        for(int i = 1; i < nums.length; i++){
            if(nums[i] != temp){
                nums[len] = nums[i];
                temp = nums[i];
                len ++;
            }
        }
        return len;
    }

    public static void main(String[] args) {
        int[] arr = {0, 0, 1, 1, 1, 2, 2, 3, 3, 4};
        System.out.println( (new removeDuplicates()).removeDuplicates(arr) );
        System.out.println(Arrays.toString(arr));
    }
}
